import React, { useEffect } from "react";
import "./assets/css/reset.css";
import { AppContainer } from "./AppStyle";
import { useRoutes } from "react-router-dom";
import routes from "./router";
import { fetchShoppingCartList } from "./store/shoppingCart";
import { useDispatch } from "react-redux";
import { useSelector } from "./store/hooks";
function App() {
  const elements = useRoutes(routes);
  const dispatch = useDispatch();
  const { token } = useSelector((state) => ({
    token: state.User.token,
  }));
  useEffect(() => {
    if (token) {
      dispatch<any>(fetchShoppingCartList());
    }
  }, [token]);
  return (
    <AppContainer>
      <div className="App">{elements}</div>
    </AppContainer>
  );
}

export default App;
